<template>
  <div class="common-layout">
    <el-container>
      <el-aside width="200px">
        <div class="title">通用后台管理系统</div>
        <el-menu :default-active="activeSlideIndex" @open="handleOpen" background-color="#2b303b" text-color="#fff" @close="handleClose" :router="true">
          <el-menu-item index="home">
            <el-icon><icon-menu /></el-icon>
            <span>系统概览</span>
          </el-menu-item>
          <el-sub-menu index="2">
            <template #title>
              <el-icon><User /></el-icon>
              <span>用户管理</span>
            </template>
            <el-menu-item-group title="管理员管理">
              <el-menu-item index="1-1">产品管理员</el-menu-item>
              <el-menu-item index="1-2">用户管理员</el-menu-item>
            </el-menu-item-group>
            <el-menu-item-group title="员工管理">
              <el-menu-item index="1-3">用户列表</el-menu-item>
            </el-menu-item-group>
          </el-sub-menu>
          <el-sub-menu index="3">
            <template #title>
              <el-icon><TakeawayBox /></el-icon>
              <span>产品管理</span>
            </template>
            <el-menu-item-group title="管理员管理">
              <el-menu-item index="1-1">产品管理员</el-menu-item>
              <el-menu-item index="1-2">用户管理员</el-menu-item>
            </el-menu-item-group>
            <el-menu-item-group title="员工管理">
              <el-menu-item index="1-3">用户列表</el-menu-item>
            </el-menu-item-group>
          </el-sub-menu>
          <el-sub-menu index="4">
            <template #title>
              <el-icon><Message /></el-icon>
              <span>消息管理</span>
            </template>
            <el-menu-item-group title="管理员管理">
              <el-menu-item index="1-1">产品管理员</el-menu-item>
              <el-menu-item index="1-2">用户管理员</el-menu-item>
            </el-menu-item-group>
            <el-menu-item-group title="员工管理">
              <el-menu-item index="1-3">用户列表</el-menu-item>
            </el-menu-item-group>
          </el-sub-menu>
          <el-menu-item index="5">
            <el-icon><Notebook /></el-icon>
            <span>合同管理</span>
          </el-menu-item>
          <el-menu-item index="6">
            <el-icon><document /></el-icon>
            <span>操作日志</span>
          </el-menu-item>
          <el-menu-item index="7">
            <el-icon><document /></el-icon>
            <span>登录日志</span>
          </el-menu-item>
          <el-menu-item index="8">
            <el-icon><setting /></el-icon>
            <span>系统设置</span>
          </el-menu-item>
        </el-menu>
      </el-aside>
      <el-container>
        <el-header>
          <el-menu :default-active="activeHeaderIndex" class="el-menu-top" mode="horizontal" text-color="#fff" background-color="#2b303b" @select="handleSelect">
            <el-menu-item index="1">首页</el-menu-item>
            <el-sub-menu index="2">
              <template #title>Workspace</template>
              <el-menu-item index="2-1">item one</el-menu-item>
              <el-menu-item index="2-2">item two</el-menu-item>
              <el-menu-item index="2-3">item three</el-menu-item>
              <el-sub-menu index="2-4">
                <template #title>item four</template>
                <el-menu-item index="2-4-1">item one</el-menu-item>
                <el-menu-item index="2-4-2">item two</el-menu-item>
                <el-menu-item index="2-4-3">item three</el-menu-item>
              </el-sub-menu>
            </el-sub-menu>
            <el-menu-item index="3">Info</el-menu-item>
            <el-menu-item index="4">Orders</el-menu-item>
          </el-menu>
          <div class="header-right">
            <div class="welcome">尊敬的xxx 欢迎登本系统</div>
            <el-icon :size="20"><Message /></el-icon>
            <el-avatar :size="24" src="https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png" />
            <el-dropdown placement="bottom-end">
              <span class="el-dropdown-link">
                设置
                <el-icon class="el-icon--right">
                  <arrow-down />
                </el-icon>
              </span>
              <template #dropdown>
                <el-dropdown-menu>
                  <el-dropdown-item>设置账户</el-dropdown-item>
                  <el-dropdown-item @click="logout">退出登录</el-dropdown-item>
                </el-dropdown-menu>
              </template>
            </el-dropdown>
          </div>
        </el-header>
        <el-main><RouterView /></el-main>
      </el-container>
    </el-container>
  </div>
</template>

<style scoped lang="scss">
.common-layout {
  width: 100%;
  height: 100%;
}

.el-aside {
  height: 100vh;
  background: #2b303b;

  .title {
    padding: 20px;
    display: flex;
    justify-content: center;
    color: #fff;
    background: #2b303b;
  }

  .el-menu-item:hover {
    background: #006eff;
  }

  :deep(.el-sub-menu__title:hover) {
    background: #006eff;
  }
}

.el-header {
  background: #2b303b;
  justify-content: space-between;
  height: 55px;
  display: flex;
  flex-direction: row;
  align-items: center;
  color: #fff;

  .el-menu-top {
    width: 800px;
  }
  .header-right {
    display: flex;
    align-items: center;

    .welcome {
      font-size: 14px;
    }
    .el-icon {
      margin: 0 20px;
    }
    .el-dropdown {
      margin-left: 20px;
    }
  }
}

.el-menu-top {
  justify-content: start;
}
</style>

<script setup lang="ts">
import router from '@/router'
import { User } from '@element-plus/icons-vue'
import { ref } from 'vue'
import { RouterView } from 'vue-router'

const activeHeaderIndex = ref('1')
const activeSlideIndex = ref('home')

const handleSelect = (key: string, keyPath: string[]) => {
  console.log(key, keyPath)
}

const handleOpen = (key: string, keyPath: string[]) => {
  console.log(key, keyPath)
}

const handleClose = (key: string, keyPath: string[]) => {
  console.log(key, keyPath)
}

const logout = () => {
  localStorage.removeItem('token')
  router.push('/login')
}
</script>
